/*
 * Copyright 2010 Chad Retz
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package org.jdocng.shared.model;

import javax.xml.bind.annotation.XmlType;

import com.google.common.annotations.GwtCompatible;
import com.google.gson.annotations.Expose;
import com.sun.javadoc.ThrowsTag;
import com.sun.javadoc.Type;

/**
 * Implementation of {@link ThrowsTag}
 *
 * @author Chad Retz
 */
@XmlType(name = "throwsTag")
@GwtCompatible(serializable = true)
@SuppressWarnings("serial")
public class ThrowsTagImpl extends TagImpl implements ThrowsTag {

    //exposed fields
    
    @Expose
    private String exception;

    @Expose
    private String exceptionComment;
    
    @Expose
    private String exceptionName;
    
    //non-exposed fields
    
    private transient ClassDocImpl exceptionLoaded;
    
    private transient Type exceptionTypeLoaded;
    
    //ThrowsTag interface impl
    
    @Override
    public ClassDocImpl exception() {
        if (exceptionLoaded == null) {
            exceptionLoaded = getContext().getClassDoc(exception);
        }
        return exceptionLoaded;
    }
    
    @Override
    public String exceptionComment() {
        return exceptionComment;
    }
    
    @Override
    public String exceptionName() {
        return exceptionName;
    }
    
    @Override
    public Type exceptionType() {
        if (exceptionTypeLoaded == null) {
            exceptionTypeLoaded = getContext().getType(exception);
        }
        return exceptionTypeLoaded;
    }
    
    //other accessors
    
    public String getException() {
        return exception;
    }
    
    public void setException(String exception) {
        this.exception = exception;
    }
    
    public void setExceptionComment(String exceptionComment) {
        this.exceptionComment = exceptionComment;
    }
    
    public void setExceptionName(String exceptionName) {
        this.exceptionName = exceptionName;
    }
}
